package org.example.framework.BeanDefinition;

import org.example.framework.BeanException.BeanException;

import java.util.ArrayList;
import java.util.List;

import static org.example.framework.BeanException.BeanException.ErrorType.NAME_RPT;

public class BeanDefinition {
    private String id;
    private Class beanClass;

    private final List<BeanProperty> propertyList;

    public BeanDefinition(){
        propertyList = new ArrayList<>();
    }

    public BeanDefinition(String id, Class clazz){
        this.id = id;
        this.beanClass = clazz;
        propertyList = new ArrayList<>();
    }

    public void addProperty(BeanProperty beanProperty) throws BeanException{
        if(beanProperty == null){
            return;
        }

        for(BeanProperty property : propertyList){
            if(property.getName().trim().equals(beanProperty.getName())){
                throw new BeanException(NAME_RPT ,"duplicate name in property");
            }
        }
        propertyList.add(beanProperty);
    }

    public List<BeanProperty> getPropertyList() {
        return propertyList;
    }

    public Class getBeanClass() {
        return beanClass;
    }
}
